"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var login_service_1 = require("../../lib/service/login.service");
var local_storage_service_1 = require("../../lib/service/local-storage.service");
var animations_1 = require("@angular/animations");
var moment = require("moment");
var LoginData = /** @class */ (function () {
    function LoginData() {
    }
    return LoginData;
}());
exports.LoginData = LoginData;
var PageTopComponent = /** @class */ (function () {
    function PageTopComponent(router, localStorageService) {
        this.router = router;
        this.localStorageService = localStorageService;
        this.hasLogin = false;
    }
    PageTopComponent.prototype.ngOnInit = function () {
        this.checkLoginInfo();
    };
    PageTopComponent.prototype.clear = function () {
        this.hasLogin = false;
        this.localStorageService.clearAll();
        this.router.navigate(['/tuike/login']);
    };
    // 检查是否登录过期
    PageTopComponent.prototype.checkLoginInfo = function () {
        var auth = this.localStorageService.getAdminInfo();
        // 创建时间
        var time = parseInt(auth.time, 10);
        // 过期时间
        var expireTime = time + 3600;
        // 当前时间
        var nowTime = parseInt(moment().format('X'), 10);
        if (expireTime < nowTime) {
            alert("登录信息过期，请重新登录");
            this.localStorageService.clearAll();
            this.router.navigate(['/admin/index']);
            return false;
        }
        else {
            this.hasLogin = true;
            this.userName = this.localStorageService.getAdminInfo().nick_name;
        }
    };
    __decorate([
        core_1.ViewChild('loginModal')
    ], PageTopComponent.prototype, "loginModal", void 0);
    PageTopComponent = __decorate([
        core_1.Component({
            selector: 'app-page-top',
            templateUrl: './page-top.component.html',
            styleUrls: ['./page-top.component.scss'],
            providers: [local_storage_service_1.LocalStorageService, login_service_1.LoginService],
            animations: [
                animations_1.trigger('flyInOut', [
                    animations_1.state('in', animations_1.style({ transform: 'translateX(0)', opacity: 1 })),
                    animations_1.transition('void => *', [
                        animations_1.style({ transform: 'translateX(50%)', opacity: 0 }),
                        animations_1.animate(300)
                    ]),
                    animations_1.transition('* => void', [
                        animations_1.animate(300, animations_1.style({ transform: 'translateX(50%)', opacity: 0 }))
                    ])
                ])
            ]
        })
    ], PageTopComponent);
    return PageTopComponent;
}());
exports.PageTopComponent = PageTopComponent;
